Skip to content

Conversation

@Will-ShaoHua
Copy link
Contributor

@Will-ShaoHua Will-ShaoHua commented Aug 15, 2025

Problem

Solution

related pr aws/aws-toolkit-vscode#7646

License

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@Will-ShaoHua Will-ShaoHua requested a review from a team as a code owner August 15, 2025 22:32
@Will-ShaoHua Will-ShaoHua changed the title fix: pure addition edit suggestion should be treated as Completions s… fix: pure addition edit suggestion should be treated as Completions suggestion instead of Edits Aug 15, 2025
@codecov-commenter
Copy link

codecov-commenter commented Aug 15, 2025

Codecov Report

❌ Patch coverage is 58.36910% with 97 lines in your changes missing coverage. Please review.
✅ Project coverage is 61.29%. Comparing base (ed8c6dd) to head (35ee185).

Files with missing lines Patch % Lines
...nguage-server/inline-completion/utils/diffUtils.ts 66.50% 67 Missing and 1 partial ⚠️
...p-codewhisperer/src/shared/codeWhispererService.ts 0.00% 19 Missing ⚠️
...inline-completion/handler/editCompletionHandler.ts 9.09% 10 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2133      +/-   ##
==========================================
+ Coverage   61.24%   61.29%   +0.05%     
==========================================
  Files         261      261              
  Lines       58291    58504     +213     
  Branches     3582     3618      +36     
==========================================
+ Hits        35699    35860     +161     
- Misses      22524    22575      +51     
- Partials       68       69       +1     
Flag Coverage Δ
unittests 61.29% <58.36%> (+0.05%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Will-ShaoHua Will-ShaoHua marked this pull request as draft August 18, 2025 21:23
@Will-ShaoHua Will-ShaoHua changed the title fix: pure addition edit suggestion should be treated as Completions suggestion instead of Edits fix: addonly EDITS should be handled as COMPLETIONS Sep 30, 2025
@Will-ShaoHua Will-ShaoHua marked this pull request as ready for review October 1, 2025 23:19
if (line.startsWith('+')) {
completionSuggestion += line.substring(1) + '\n'
isInAdditionBlock = true
} else if (isInAdditionBlock && line.startsWith(' ')) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we add this check? Should the addition only contain lines with + at the beginning?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i updated this part of code, it should be

 if (line.startsWith('+')) {
            completionSuggestion += line.substring(1) + '\n'
            isInAdditionBlock = true
        } else if (isInAdditionBlock && !line.startsWith('+')) {
            // End of addition block
            isInAdditionBlock = false
        }

*
**/
// TODO: should refine the logic here more, possibly find the first non-empty minus/plus if possible
if (firstMinusIndex + 1 === firstPlusIndex) {
Copy link
Contributor

@atonaamz atonaamz Oct 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what if there are insertion on multiple consecutive lines (like - - + +)? Will it be counted as edit or completion?

}

if (firstMinusIndex === -1 && firstPlusIndex !== -1) {
return 'addOnly'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will the + line always be after cursor position?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's parsing the raw unified diff so cursor position here is not relevant. Cursor position will only be critical after we are sure if it's a COMPLETION and should we render it or not.

const relevantLines = d.linesWithoutHeaders

if (firstMinusIndex === -1 && firstPlusIndex === -1) {
return 'edit'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible that there are no + and - lines?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

theoretically no, we do this way beause currently all suggestions coming back from Qwen is "EDITS" so we can safely assume they are EDTIS and let clients to decide if we will render it or not, i.e. delegate the resposibility to the 3rd party unidfied diff lib we are using in vscode.

): { suggestionContent: string; type: SuggestionType } {
const diffCategory = categorizeUnifieddiff(unifiedDiff)
if (diffCategory === 'addOnly') {
const udiff = readUdiff(unifiedDiff)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we just call this method one time and pass it to categorizeUnifieddiff?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

): { suggestionContent: string; type: SuggestionType } {
const diffCategory = categorizeUnifieddiff(unifiedDiff)
if (diffCategory === 'addOnly') {
const udiff = readUdiff(unifiedDiff)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where do we use this udiff?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep you are right, it's not used here, removed.

}
}

// Backward compatibility, completions will be returned if predictinoType is not specified (either Completion or Edit)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit, predictionType

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

}

// TODO: current implementation here assumes service only return 1 chunk of edits (consecutive lines) and hacky
export function extractAdditions(unifiedDiff: string): string {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Few questions
The function stops processing when it hits a context line after additions right?

  • What happens with separated addition blocks in the same diff?
  • Do we handle multi-hunk diffs correctly?
  • Should we extract ALL '+' lines regardless of context interruptions?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. yes it's based on the assumption service doesn't return multi chunk of edits
  2. no
  3. i assume this is also for the "multi-hunk" scenarios and no we dont handle it now

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

at the very least, we need to add if "multi-hunk" then EDITS

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but i will take it as follow up as service currently doesn't return such suggestion (multi hunk)

@Will-ShaoHua Will-ShaoHua changed the base branch from main to feature/nep October 2, 2025 17:12
@Will-ShaoHua Will-ShaoHua changed the base branch from feature/nep to main October 2, 2025 20:49
@Will-ShaoHua Will-ShaoHua merged commit 4f5a9da into aws:main Oct 7, 2025
6 checks passed
@Will-ShaoHua Will-ShaoHua deleted the fix branch October 7, 2025 16:44
Will-ShaoHua added a commit to Will-ShaoHua/language-servers that referenced this pull request Oct 8, 2025
Will-ShaoHua added a commit to Will-ShaoHua/language-servers that referenced this pull request Oct 8, 2025
bywang56 pushed a commit that referenced this pull request Oct 9, 2025
* fix: patch #2133 and handle more variants of FIM suggestions

* fix: only consider FIM if the first edit line matches trigger position

* fix: test

---------

Co-authored-by: atontb <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants